package services

import (
	"ContentSystem/internal/dao"
	"ContentSystem/internal/models"
	"ContentSystem/internal/process"
	"github.com/redis/go-redis/v9"
	goflow "github.com/s8sg/goflow/v1"
	"gorm.io/gorm"
)

type CmsApp struct {
	db         *gorm.DB
	contentDao *dao.ContentDao
	accountDao *dao.AccountDao
	rdb        *redis.Client
	f          *goflow.FlowService
}

func NewCmsApp() *CmsApp {
	app := &CmsApp{}
	app.db = models.InitDataBase(models.MySQLConf{
		Address:         "159.75.92.211:13306",
		DbName:          "mall",
		Username:        "root",
		Password:        "12345678",
		MaxOpenConns:    10,
		MaxIdleConns:    10,
		ConnMaxLifetime: 100000,
	})
	app.rdb = models.ConnRdb()
	app.contentDao = dao.NewContentDao(app.db)
	app.accountDao = dao.NewAccountDao(app.db)
	app.f = flowService()
	go process.ExecContentFlow(app.db)
	return app
}

func flowService() *goflow.FlowService {
	return &goflow.FlowService{
		Port:              9092,
		RedisURL:          "localhost:6379",
		WorkerConcurrency: 5,
	}
}
